/***************************************************************
 * Name:      genobotsMain.h
 * Purpose:   Defines Application Frame
 * Author:    Ramon van Dam, Bart van der Drift & Susan Laraghy
 * Created:   2008-10-20
 * Copyright: Ramon van Dam, Bart van der Drift & Susan Laraghy
 * License:
 **************************************************************/

#ifndef GENOBOTSMAIN_H
#define GENOBOTSMAIN_H

//(*Headers(genobotsFrame)
#include <wx/treectrl.h>
#include <wx/notebook.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/menu.h>
#include <wx/textctrl.h>
#include <wx/checkbox.h>
#include <wx/spinctrl.h>
#include <wx/toolbar.h>
#include <wx/slider.h>
#include <wx/panel.h>
#include <wx/grid.h>
#include <wx/choice.h>
#include <wx/button.h>
#include <wx/frame.h>
#include <wx/timer.h>
#include <wx/statusbr.h>
//*)
#include "defines.h"
#include "settings.h"
#include "genobots.h"
#include "botcode.h"

using namespace std;

class genobotsFrame;

class GenoCanvas : public wxWindow {
  public:
    // functions
    GenoCanvas(wxWindow *parent, GenoBots *theGenobots);
    virtual ~GenoCanvas();
    wxPoint computeCell(wxPoint);
    void    DrawGrid(wxPaintDC dc, wxInt32 widthPerCell, wxInt32 heightPerCell);
    int     GetMin(int a, int b);
    int     GetRound(float f);
    // variables
    bool            drawAll;
    GenoBots        *genobots;
    wxPoint         orig;
    pair<int, int>  selected;
    genobotsFrame   *theFrame;
    settings        *theSettings;
  private:
    DECLARE_EVENT_TABLE()
    // event handlers
    void OnEraseBackground(wxEraseEvent& WXUNUSED(event));
    void OnPaint(wxPaintEvent& event);
    void OnSize(wxSizeEvent& event);
    void OnLeftUp(wxMouseEvent& event);
    void OnRightUp(wxMouseEvent& event);
    // variables
    int width, height, cellsize;
};

class genobotsFrame: public wxFrame
{
    public:

        genobotsFrame(wxWindow* parent,wxWindowID id = -1);
        virtual ~genobotsFrame();
        void ShowMenuRightBot();
        void ShowMenuRightNoBot();
        void UpdateBotPanel();
        void UpdateTree();
        void UpdateUI();
        void UpdateStatusBar();

    private:

        //(*Handlers(genobotsFrame)
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void OnToolStartClicked(wxCommandEvent& event);
        void OnToolStopClicked(wxCommandEvent& event);
        void OnG_timer1Trigger(wxTimerEvent& event);
        void OnSpnSpeedChange(wxSpinEvent& event);
        void OnGenoCanvasRightUp(wxMouseEvent& event);
        void OnMenuFileNewSelected(wxCommandEvent& event);
        void OnMenuLoopStartSelected(wxCommandEvent& event);
        void OnMenuLoopStopSelected(wxCommandEvent& event);
        void OnMenuLoopStepSelected(wxCommandEvent& event);
        void OnButNewClick(wxCommandEvent& event);
        void OnToolnewClicked(wxCommandEvent& event);
        void OnGenoCanvasLeftUp(wxMouseEvent& event);
        void OnMenuRightBotDeleteSelected(wxCommandEvent& event);
        void OnMenuRightNoBotAddBotSelected(wxCommandEvent& event);
        void OnMenuFileSourceSelected(wxCommandEvent& event);
        void OnMenuBotsAddSuperBotSelected(wxCommandEvent& event);
        void OnbutClearClick(wxCommandEvent& event);
        void OnButFoodClick(wxCommandEvent& event);
        void OnChkBotFollowClick(wxCommandEvent& event);
        void OnNotebook1PageChanged(wxNotebookEvent& event);
        void OnSldSpeedCmdScroll(wxScrollEvent& event);
        void OnSldSpeedCmdScrollThumbTrack(wxScrollEvent& event);
        void OnSldSpeedCmdScrollChanged(wxScrollEvent& event);
        void OnSpnFoodChanceChange(wxSpinEvent& event);
        void OnSpnFoodIntervalChange(wxSpinEvent& event);
        void OnSpnFoodHealthChange(wxSpinEvent& event);
        void OnSpnInitBotChanceChange(wxSpinEvent& event);
        void OnSpnInitBotHealthChange(wxSpinEvent& event);
        void OnChkEvolveClick(wxCommandEvent& event);
        void OnChkUseLogClick(wxCommandEvent& event);
        void OnSpnEvoChanceChange(wxSpinEvent& event);
        void OnSpnEvoAmountChange(wxSpinEvent& event);
        void OnSpnMutateChanceChange(wxSpinEvent& event);
        void OnMenuFilePlotSelected(wxCommandEvent& event);
        void OnToolPlotClicked(wxCommandEvent& event);
        void OnChkMutateClick(wxCommandEvent& event);
        void OnChcQualitySelect(wxCommandEvent& event);
        void OnButBotsClick(wxCommandEvent& event);
        void OnToolAddBotsClicked(wxCommandEvent& event);
        void OnToolFoodClicked(wxCommandEvent& event);
        void OnToolBarClearClick(wxCommandEvent& event);
        void OnSpnFightDamageChange(wxSpinEvent& event);
        void OnToolBarSourceClick(wxCommandEvent& event);
        void OnToolBarSuperbotClick(wxCommandEvent& event);
        void OnToolBarRestartClick(wxCommandEvent& event);
        //*)

        //(*Identifiers(genobotsFrame)
        static const long ID_STATICTEXT4;
        static const long ID_TREECTRL1;
        static const long ID_STATICTEXT22;
        static const long ID_TEXTCTRL4;
        static const long ID_CHECKBOX3;
        static const long ID_PANEL2;
        static const long ID_GENOCANVAS;
        static const long ID_STATICTEXT5;
        static const long ID_STATICTEXT6;
        static const long ID_STATICTEXT7;
        static const long ID_STATICTEXT8;
        static const long ID_STATICTEXT9;
        static const long ID_STATICTEXT10;
        static const long ID_STATICTEXT13;
        static const long ID_STATICTEXT14;
        static const long ID_STATICTEXT11;
        static const long ID_STATICTEXT12;
        static const long ID_STATICTEXT15;
        static const long ID_CHECKBOX1;
        static const long ID_GRID1;
        static const long ID_TEXTCTRL3;
        static const long ID_PANEL3;
        static const long ID_STATICTEXT19;
        static const long ID_SPINCTRL5;
        static const long ID_STATICTEXT20;
        static const long ID_SPINCTRL6;
        static const long ID_STATICTEXT16;
        static const long ID_SPINCTRL2;
        static const long ID_STATICTEXT17;
        static const long ID_SPINCTRL3;
        static const long ID_STATICTEXT18;
        static const long ID_SPINCTRL4;
        static const long ID_STATICTEXT28;
        static const long ID_SPINCTRL10;
        static const long ID_STATICTEXT21;
        static const long ID_CHECKBOX2;
        static const long ID_STATICTEXT23;
        static const long ID_CHECKBOX4;
        static const long ID_STATICTEXT24;
        static const long ID_SPINCTRL7;
        static const long ID_STATICTEXT25;
        static const long ID_SPINCTRL8;
        static const long ID_STATICTEXT26;
        static const long ID_SPINCTRL9;
        static const long ID_STATICTEXT27;
        static const long ID_CHOICE1;
        static const long ID_PANEL4;
        static const long ID_NOTEBOOK1;
        static const long ID_STATICTEXT1;
        static const long ID_SLIDER1;
        static const long ID_SPINCTRL1;
        static const long ID_STATICTEXT2;
        static const long ID_TEXTCTRL1;
        static const long ID_STATICTEXT3;
        static const long ID_TEXTCTRL2;
        static const long ID_BUTTON1;
        static const long ID_BUTTON2;
        static const long ID_BUTTON3;
        static const long ID_BUTTON4;
        static const long ID_PANEL1;
        static const long idMenuNew;
        static const long isMenuSourceEditor;
        static const long isMenuPlot;
        static const long idMenuQuit;
        static const long idMenuBotsAddSuperBot;
        static const long idMenuLoopStart;
        static const long idMenuLoopStep;
        static const long idMenuLoopStop;
        static const long idMenuAbout;
        static const long ID_STATUSBAR1;
        static const long ID_TOOL_RESTART;
        static const long ID_TOOL_CLEAR;
        static const long ID_ADD_SUPERBOT;
        static const long ID_TOOL_BOTS;
        static const long ID_TOOL_FOOD;
        static const long ID_TOOL_PLOT;
        static const long ID_TOOL_SOURCE;
        static const long ID_TOOL_NEW;
        static const long ID_TOOL_START;
        static const long ID_TOOL_STOP;
        static const long ID_TOOLBAR1;
        static const long ID_TIMER1;
        static const long ID_DELETE_BOT;
        static const long ID_ADD_BOT;
        //*)

        //(*Declarations(genobotsFrame)
        wxStaticText* StaticText10;
        wxStaticText* stcBotDirection;
        wxMenuItem* menuRightNoBotAddBot;
        wxStaticText* StaticText22;
        wxStaticText* StaticText9;
        wxToolBarToolBase* ToolBarItem4;
        wxStatusBar* statusbar;
        wxStaticText* StaticText20;
        wxCheckBox* chkEvolve;
        wxSpinCtrl* spnEvoAmount;
        wxToolBar* ToolBar1;
        wxTimer g_timer1;
        wxStaticText* stcBotLineNr;
        wxToolBarToolBase* ToolBarItem9;
        wxSpinCtrl* spnInitBotChance;
        wxCheckBox* chkUseLog;
        wxNotebook* Notebook1;
        wxToolBarToolBase* ToolBarItem3;
        wxTextCtrl* txtNumColumns;
        wxStaticText* StaticText13;
        wxStaticText* StaticText2;
        wxPanel* Panel4;
        wxStaticText* StaticText14;
        wxSpinCtrl* spnInitBotHealth;
        wxStaticText* stcBotHealth;
        wxMenuItem* menuFileSource;
        wxMenu* Menu3;
        wxToolBarToolBase* ToolBarItem10;
        wxStaticText* StaticText6;
        wxChoice* chcQuality;
        wxMenuItem* menuFilePlot;
        wxStaticText* StaticText19;
        wxButton* butClear;
        wxStaticText* StaticText8;
        wxStaticText* StaticText11;
        wxStaticText* StaticText18;
        wxPanel* Panel1;
        wxSpinCtrl* spnSpeed;
        wxStaticText* StaticText1;
        wxStaticText* StaticText3;
        wxTextCtrl* txtLog;
        wxMenuItem* menuLoopStep;
        wxMenuItem* menuLoopStart;
        wxCheckBox* chkBotFollow;
        wxStaticText* StaticText21;
        wxPanel* Panel3;
        wxToolBarToolBase* ToolBarItem6;
        wxSpinCtrl* spnMutateChance;
        wxStaticText* StaticText23;
        wxSpinCtrl* spnFoodHealth;
        wxToolBarToolBase* ToolBarItem1;
        wxMenuItem* MenuItem3;
        wxCheckBox* chkMutate;
        wxTextCtrl* txtBotCode;
        wxButton* butNew;
        wxSpinCtrl* spnFightDamage;
        wxTreeCtrl* treeLoadedBots;
        GenoCanvas* genoCanvas;
        wxStaticText* StaticText5;
        wxStaticText* StaticText7;
        wxStaticText* stcBotSuperbot;
        wxTextCtrl* txtNumRows;
        wxToolBarToolBase* ToolBarItem5;
        wxSpinCtrl* spnFoodChance;
        wxButton* butBots;
        wxStaticText* StaticText15;
        wxStaticText* StaticText12;
        wxButton* butFood;
        wxSpinCtrl* spnFoodInterval;
        wxSpinCtrl* spnEvoChance;
        wxGrid* grdBotMemory;
        wxToolBarToolBase* ToolBarItem8;
        wxPanel* Panel2;
        wxSlider* sldSpeed;
        wxMenuItem* menuLoopStop;
        wxStaticText* StaticText17;
        wxStaticText* StaticText4;
        wxMenuItem* menuFileNew;
        wxMenu menuRightBot;
        wxMenu menuRightNoBot;
        wxToolBarToolBase* ToolBarItem2;
        wxStaticText* stcBotStarttic;
        wxStaticText* StaticText16;
        wxMenu* Menu4;
        wxToolBarToolBase* ToolBarItem7;
        //*)

        // own functions
        void OnNew();
        void OnStart();
        void OnStop();
        void OnStep();

        // variables
        GenoBots *genobots;
        bool g_running;
        bool g_topspeed;
        long g_interval;
        long g_tics;
        bool g_busy;
        settings *theSettings;
        wxTreeItemId treeRoot;
        vector<wxTreeItemId> treeIds;
        vector<superBot*> treeSuperbots;

        DECLARE_EVENT_TABLE()
};

#endif // GENOBOTSMAIN_H
